// SmpWatcherView.h : interface of the CSmpWatcherView class
//


#pragma once

#include "../MCHdTree/CMCHTreeView.h"
#include "./CDIADataWtch.h"
#include "cmemspace.h"

class CSmpWatcherView : public CMCHTreeView
{
private:
	struct CWtchViewItem
	{
		CWtchViewItem(CDIAViewItem* pDiaVI, BOOL fE=FALSE)
			:pdiaVI(pDiaVI), fExpand(fE), dwChldNum(0)
		{};
		~CWtchViewItem(){};

	// display item
		std::auto_ptr<CDIAViewItem> pdiaVI;

	//display control
		BOOL fExpand;
		DWORD dwChldNum;
	};

protected: // create from serialization only
	CSmpWatcherView();
	DECLARE_DYNCREATE(CSmpWatcherView)

// Attributes
public:
	CSmpWatcherDoc* GetDocument() const;

// Operations
public:

// Overrides
	public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
	virtual void OnInitialUpdate(); // called first time after construct

// Implementation
public:
	virtual ~CSmpWatcherView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()

public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnEditEnd(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnEditBgn(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTvnItemExpand(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTvnDeleteitem(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnTvnGetItemInfo(NMHDR *pNMHDR, LRESULT *pResult);

private:
	DWORD InsertWtch(CString* pcstrType, DWORD dwAddr=0, CString* pcstrName=NULL);
	HTREEITEM InsertSymbol(CDIAViewItem* pDiaVI, HTREEITEM hParent=TVI_ROOT, HTREEITEM hInsertAfter=TVI_LAST, BOOL fExpandPtr=TRUE, BOOL fRecurse=FALSE);
	VOID RefreshSubItem(HTREEITEM hItem);

private:
	void InsertChild(HTREEITEM hItem, CWtchViewItem* pWtchItem, BOOL fExpandPtr, BOOL fRecurs=FALSE);

private:
	static BOOL RefreshForEach(VOID* pv, HTREEITEM hItem){return ((CSmpWatcherView*)pv)->RefreshForEach(hItem);};
	BOOL RefreshForEach(HTREEITEM hItem);

private:
	BOOL UpdateAddr(HTREEITEM htreeitem, DWORD dwAddr, BOOL fBaseAddr, IMemSpace* pIMemSpace=NULL);
	BOOL UpdateVal(CDIAViewItem* pDiaVI, IMemSpace* pIMemSpace=NULL, CString* pcstrDisVal=NULL);
	BOOL UpdateVal(CDIAViewItem* pDiaVI, CString* pcstrUpdateVal, CString* pcstrDisVal=NULL);

public:
	BOOL ModifyDim(HTREEITEM htreeitem);

private:
	static TCHAR* m_pszHdS[];
	static DWORD m_dwHdWdthS[];
	static DWORD m_dwHdFlgS[];
	static DWORD m_dwClmn;

private:
	CSymbolFinder* m_pSymbFinder;

public:
	afx_msg void OnAddwatch();
	afx_msg void OnRefresh();
};

#ifndef _DEBUG  // debug version in SmpWatcherView.cpp
inline CSmpWatcherDoc* CSmpWatcherView::GetDocument() const
   { return reinterpret_cast<CSmpWatcherDoc*>(m_pDocument); }
#endif

